namespace Crux.Core.Commands;
/// <summary>
/// CommandResult
/// </summary>
public class CommandResult
    : ICommandExecuteResult
{
    /// <summary>
    /// 是否成功
    /// </summary>
    public bool Success { get; protected set; }
    /// <summary>
    /// 信息
    /// </summary>
    public string? Message { get; protected set; }
    /// <summary>
    /// 私有化构造函数
    /// </summary>
    private CommandResult()
    {
    }
    /// <summary>
    /// 构造函数
    /// </summary>
    /// <param name="success">是否成功</param>
    /// <param name="message">信息</param>
    protected CommandResult(
        bool success = true,
        string? message = null)
    {
        if (!success &&
            string.IsNullOrEmpty(message))
            throw new ArgumentNullException("message must be not null");

        Success = success;
        Message = message;
    }
    /// <summary>
    /// 成功
    /// </summary>
    /// <returns></returns>
    public static CommandResult Successed()
        => new CommandResult(success: true);
    /// <summary>
    /// 失败
    /// </summary>
    /// <param name="message"></param>
    /// <returns></returns>
    public static CommandResult Failed(string message)
        => new CommandResult(success: false, message: message);
    /// <summary>
    /// 解构函数
    /// </summary>
    /// <param name="success">是否成功</param>
    /// <param name="message">信息</param>
    public void Deconstruct(out bool success, out string? message)
    {
        success = Success;
        message = Message;
    }
    /// <summary>
    /// 解构函数
    /// </summary>
    /// <param name="success">是否成功</param>
    public void Deconstruct(out bool success)
    {
        success = Success;
    }
}
